package service

import (
	"saas-app/app/dao"
	"saas-app/app/model"

	"github.com/gogf/gf/database/gdb"
)

type CourseMemberRepository interface {
	GetCourseMember(course_id uint) (gdb.Result, error)
	CreateCourseMember(member *model.CourseMember) bool
}

type courseMember struct{}

func CourseMemberService() CourseMemberRepository {
	return &courseMember{}
}

func (c courseMember) GetCourseMember(course_id uint) (gdb.Result, error) {
	members, err := dao.CourseMember.Where("course_id = ?", course_id).FindAll()
	return members, err
}

func (c courseMember) CreateCourseMember(member *model.CourseMember) bool {
	_, err := dao.ClassMember.Save(member)
	return err == nil
}
